package com.ruoyi.back.service.impl

import com.baomidou.mybatisplus.extension.kotlin.KtQueryWrapper
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
import com.ruoyi.app.common.Data
import com.ruoyi.app.common.Ok
import com.ruoyi.back.domain.v2.Task
import com.ruoyi.back.domain.v2.TaskCodeShare
import com.ruoyi.back.domain.v2.TaskShare
import com.ruoyi.back.mapper.TaskMapper
import com.ruoyi.back.service.TaskCodeShareService
import com.ruoyi.back.service.TaskService
import com.ruoyi.back.service.TaskShareService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service

@Service
class TaskServiceImpl : ServiceImpl<TaskMapper, Task>(), TaskService {

    @Autowired
    private lateinit var taskShareService: TaskShareService
    @Autowired
    private lateinit var taskCodeShareService: TaskCodeShareService

    override fun updateTask(task: Task): Data<Boolean> = Ok("更新成功", updateById(task))

    override fun taskShareSetting(taskShare: TaskShare): Data<Boolean> = Ok("更新成功", taskShareService.updateById(taskShare))

    override fun taskCodeShareSetting(taskCodeShare: TaskCodeShare): Data<Boolean> = Ok("更新成功", taskCodeShareService.updateById(taskCodeShare))

    override fun taskList(channelType: Int): Data<List<Task>> = Ok("获取任务列表成功", list(KtQueryWrapper(Task::class.java)
        .eq(Task::channelType, channelType)))

    override fun taskShare(taskId: Long): Data<TaskShare> = Ok("获取分享设置成功", taskShareService.getOne(KtQueryWrapper(TaskShare::class.java)
        .eq(TaskShare::taskId, taskId)))

    override fun taskCodeShare(taskId: Long): Data<TaskCodeShare> = Ok("获取文案分享设置成功", taskCodeShareService.getOne(KtQueryWrapper(TaskCodeShare::class.java)
        .eq(TaskShare::taskId, taskId)))
}